<% if mobile? %>
<section class="mobile-orders-index">
  <% content_for :mobile_menu do %>
  <a href=""></a>
  <% end %>
  <% content_for :app_back do %>
  <a href="/">
    <i class="icon-arrow-left"></i>
  </a>
  <% end %>
  <% content_for :app_title do %>
    <ul class="mine-tabs">
      <li class="<%= 'active' if request.path =~ /dashboard\/orders/ %>"><a href="/dashboard/orders">我的订单</a></li>
      <li class="<%= 'active' if request.path =~ /dashboard\/addresses/ %>"><a href="/dashboard/addresses">我的地址</a></li>
    </ul>
  <% end %>
  <% content_for :app_action do %>
  <a href=""></a>
  <% end %>

  <ul class="state-ul">
    <li class="<%= params[:state].blank? ? 'active' : '' %>"><a href="/dashboard/orders">全部</a></li>
    <li class="<%= params[:state] == 'unpaid' ? 'active' : '' %>"><a href="/dashboard/orders?state=unpaid">待付款</a></li>
    <li class="<%= params[:state] == 'survey_pending' ? 'active' : '' %>"><a href="/dashboard/orders?state=survey_pending">待测量</a></li>
    <li class="<%= params[:state] == 'install_pending' ? 'active' : '' %>"><a href="/dashboard/orders?state=install_pending">待安装</a></li>
  </ul>

  <% if @orders.present? %>
    <ul class="order-ul">
      <% @orders.each do |order| %>
        <li class="order-item">
          <div class="top">
            <div class="pull-right text-green"><%= order.state_label %></div>
            <% if order.order_type != 'normal' %>
              <span>测量单</span>
            <% end %>
            订单编号：<%= order.order_no %>
          </div>

          <% if order.normal? %>
            <% order.order_items.each_with_index do |line, index| %>
              <% product = line.product %>
              <a href="<%= product_path(product.id) %>" class="mid">
                <%= product_small_img(product) %>
                <h1><%= product.title %></h1>
                <div>
                  <span class="text-dark">￥<%= product.msrp %></span>
                  <br>
                  * <%= line.quantity %>
                </div>
              </a>
            <% end -%>
          <% else %>
            <% survey_fee = order.reserve.survey_fee %>
            <a class="mid">
              <h1><%= survey_fee.name %></h1>
              <div>
                <span class="text-dark">￥<%= survey_fee.amount %></span>
                <br>
                * 1
              </div>
            </a>
          <% end %>

          <div class="bottom">
            <div class="">
              合计：
              <span class="text-red">￥<%= order.total_money %></span>
            </div>

            <div class="btns">
              <%= render partial: 'mobile_button', locals: { order: order } %>
              <a class="order-list-btn default" href="<%= dashboard_order_path order %>">查看订单</a>
            </div>
          </div>
        </li>
      <% end %>
    </ul>
  <% else %>
    <div class="mobile-empty-data">
      <i class="fa fa-commenting-o"></i>
      <span>暂无数据</span>
    </div>
  <% end %>
</section>

<% else %>
<% breadcrumb :dashboard_orders %>

<div class="dashboard-orders-index">

    <div class="row menu-list-row">
        <div class="col-sm-3" style="">
            <%= render partial: 'dashboard/left_menu' -%>
        </div>

        <div class="col-sm-9">
            <div class="panel">

                <!--
                <div class="panel-heading types-head">
                    <ul>
                        <li class="active">全部订单</li>
                        <li>待付款</li>
                        <li>待收货</li>
                        <li>待评价</li>
                        <li>[TODO]根据订单类型不同，这里订单状态不同</li>
                    </ul>
                </div>
                -->

                <div class="panel-body">
                  <div class="row order-item-head" style="font-weight: bold;">
                    <div class="col-sm-6">
                      <span class="pull-right">
                        小计
                      </span>
                      <div class="pull-left">
                        订单详情
                      </div>
                    </div>
                    <div class="col-sm-2 text-right">应付总额</div>
                    <div class="col-sm-2">订单状态</div>
                    <div class="col-sm-2">操作</div>
                  </div>

                  <% @orders.each do |order| %>
                    <div class="row order-item">
                      <div class="row margin-reset item-top">
                        <div class="col-sm-10">
                          <span class="<%= order.order_type == 'normal' ? 'normal-class' : 'other-class'%>"><%= order.order_type_i18n %></span>
                          <span>订单编号：</span><span class="text-gray"><%= order.order_no %></span>
                          <small class="text-gray" style="margin-left: 30px;"><%= order.created_at.to_s(:db) %></small>
                        </div>
                        <div class="col-sm-2">
                          <a href="<%= dashboard_order_path order %>">
                            查看订单详情
                            <i class="fa fa-angle-double-right"></i>
                          </a>
                        </div>
                      </div>

                      <div class="row margin-reset item-info">
                        <div class="col-sm-6 img-title-row <%= order.order_items == 0 && order.normal? || order.reserve.present? ? 'take_way' : '' %>">
                          <% if order.normal? %>
                            <% order.order_items.each_with_index do |line, index| %>
                              <% product = line.product %>
                              <div class="row margin-reset">
                                <div class="pull-right gray-color"><%= product.msrp %> * <%= line.quantity %></div>
                                <a href="<%= product_path(product.id) %>">
                                  <%= product_small_img_1(product, 'product-img') %>
                                  <p><%= product.title %></p>
                                </a>
                              </div>

                            <% end -%>
                          <% else %>
                            <% survey_fee = order.reserve.survey_fee %>
                            <div class="row margin-reset">
                              <div class="pull-right gray-color"><%= survey_fee.amount %> * 1</div>
                              <div class="survey_fee">
                                <%= survey_fee.name %>
                              </div>
                            </div>
                          <% end %>
                        </div>
                        <div class="col-sm-2 text-right red-color">
                          ￥<%= order.total_money %>
                        </div>
                        <div class="col-sm-2 gray-color">
                          <%= order.state_label %>
                        </div>
                        <div class="col-sm-2">
                          <%= render partial: "button", locals: { order: order } %>
                        </div>
                      </div>
                    </div>
                  <% end -%>
                </div>

            </div>
            <div><%= render partial: 'shared/common_pagination', locals: { pagination: @orders } %></div>
        </div>
    </div>

</div>
<% end %>
